Received: from alaska.et.byu.edu by darth.byu.edu (NX5.67d/NX3.0M)
id AA00815; Wed, 6 Jul 94 14:00:18 -0600
Received: from YVAX2.BYU.EDU by alaska.et.byu.edu; Wed, 6 Jul 1994 09:19:36 -0600
Received: from DIRECTORY-DAEMON by yvax.byu.edu (PMDF V4.3-7 #7277)
id <01HEDQ4O3X0W8Y4WUZ@yvax.byu.edu>; Wed, 6 Jul 1994 09:19:04 MDT
Received: from alaska.et.byu.edu by yvax.byu.edu (PMDF V4.3-7 #7277)
id <01HEDQ4I36688Y4XS5@yvax.byu.edu>; Wed, 6 Jul 1994 09:18:55 MDT
Received: from acs1.byu.edu by alaska.et.byu.edu; Wed, 6 Jul 1994 09:13:48 -0600
Received: from DIRECTORY-DAEMON by yvax.byu.edu (PMDF V4.3-7 #7277)
id <01HEDPI97AW09LUXZU@yvax.byu.edu>; Wed, 6 Jul 1994 09:01:46 MDT
Received: from NeXT.COM by yvax.byu.edu (PMDF V4.3-7 #7277)
id <01HEDPI528808Y4XM0@yvax.byu.edu>; Wed, 6 Jul 1994 09:01:40 MDT
Received: from lemming by oz.NeXT.COM (NX5.67e/NeXT0.1-Aleph-bf)
id AA10006; Wed, 6 Jul 94 08:00:25 -0700
Received: by lemming.next.com (NX5.67e/NX3.0X) id AA02825; Wed,
6 Jul 94 08:00:20 -0700
Received: by NeXT.Mailer (1.112.1)
Date: Wed, 06 Jul 1994 08:00:16 -0700
From: Ali Ozer <Ali_Ozer@NeXT.COM>
Subject: Re: Foundation and Misc
To: bruce@trwlasd.com
Cc: misckit@byu.edu
Message-Id: <9407061500.AA10006@oz.NeXT.COM>
Mime-Version: 1.0 (NeXT Mail 3.3 v112.1)
Content-Type: text/plain
Content-Transfer-Encoding: 7BIT
>I thought about this, and I don't like any of the real solutions.
>Don's comment about NSString being a class cluster raises
>some interesting questions. How do you affect the cluster without
>having to subclass each piece? What about private API? Does
>it (private API) make use of methods that you would want
>to override (in order to complete the subclass responsibilities)?
>What the heck do you do?
Subclassing a class cluster isn't difficult, provided the primitives are
clearly documented. In the case of the foundation clusters, they are. (For instance, NSString has two primitives, length and characterAtIndex:. For performance it's recommended that you also override getCharacters:range:. NSMutableString adds another primitive.)
In your subclass of NSString, you provide your own custom implementation,
and implement these three methods. Or, instead of providing your own custom implementation, you may just point to an instance of NSString, and forward
these three methods. You may also choose to implement other NSString
methods. Finally, you implement any init methods you need; in the case of
NSString the only init method you inherit is the abstract one, init.
The summer issue of NXApp has an article about subclassing class clusters.
>There's another disadvantage: You can't subclass them [categories],
>nor can you access any overriden methods. The latter is not as
>likely given that you cannot add state (ivars) in Categories.
My proposal was to use categories to add additional behavior to the abstract
NSString class. I'm not proposing overriding methods in NSString (this is not legal anyway). One you've added behavior like this to NSString, then all subclassers of NSString get those methods. A subclasser may override them, while still accessing the overridden implementations. So I don't see a disadvantage here.
Ali
Begin forwarded message:
From: Bruce McKenzie <bruce@trwlasd.com>
Date: 1994-07-05 13:33:54 -0700
To: Ali_Ozer@next.com (Ali Ozer)
Subject: Re: Foundation and Misc
Cc: misckit@byu.edu
content-transfer-encoding: 7BIT
> From: Ali_Ozer@NeXT.COM (Ali Ozer)
> Another option is to add the rich set of MiscString methods to NSString via> categories. The advantage of this approach would be that MiscString and
> NSString would be interchangeable, and any NSString, even one created and
> returned by the kit would respond to MiscString methods, avoiding consumers> from having to create MiscStrings from NSStrings all over the place. Also
> you would not have to deal with Unicode issues.
>
> I can think of two disadvantages to this:
> 1. Performance: These methods would have to go through NSString's primitives
> 2. You lose any state MiscString has which NSString doesn't
There's another disadvantage: You can't subclass them, nor can you access
any overriden methods. The latter is not as likely given that you cannot add state (ivars) in Categories.
I thought about this, and I don't like any of the real solutions. Don's
comment about NSString being a class cluster raises some interesting
questions. How do you affect the cluster without having to subclass each
piece? What about private API? Does it (private API) make use of methods
that you would want to override (in order to complete the subclass
responsibilities)? What the heck do you do?
---
Bruce McKenzie (spuds@netcom.com, NeXTMail welcome)
Atlas Software Ventures, Inc.
PO Box 1299, Santa Clara, CA 95052-1299
800/278-9909 (ASV-9909)
*** Software Development, specializing in NEXTSTEP ***